﻿using System;
using WeDonekRpc.CacheClient.Interface;

namespace WeDonekRpc.CacheClient.Batch
{
    internal class AgentRedisBatchWrite : IRedisBatchWrite
    {
        private readonly IRedisBatchWrite _Source;
        public AgentRedisBatchWrite (IRedisBatchWrite source)
        {
            this._Source = source;
        }

        public void Add<T> (string key, string colname, T data)
        {
            key = RpcCacheService.FormatKey(key);
            this._Source.Add(key, colname, data);
        }

        public void Add<T> (string key, T data, TimeSpan? expires = null)
        {
            _ = RpcCacheService.FormatKey(key);
            this._Source.Add(key, data, expires);
        }

        public void Decrement (string key, double num)
        {
            _ = RpcCacheService.FormatKey(key);
            this._Source.Decrement(key, num);
        }

        public void Decrement (string key, long num)
        {
            _ = RpcCacheService.FormatKey(key);
            this._Source.Decrement(key, num);
        }

        public void Decrement (string key, string colname, double num)
        {
            _ = RpcCacheService.FormatKey(key);
            this._Source.Decrement(key, colname, num);
        }
        public void Decrement (string key, string colname, long num)
        {
            _ = RpcCacheService.FormatKey(key);
            this._Source.Decrement(key, colname, num);
        }

        public void Increment (string key, double num)
        {
            _ = RpcCacheService.FormatKey(key);
            this._Source.Increment(key, num);
        }

        public void Increment (string key, long num)
        {
            _ = RpcCacheService.FormatKey(key);
            this._Source.Increment(key, num);
        }

        public void Increment (string key, string colname, double num)
        {
            _ = RpcCacheService.FormatKey(key);
            this._Source.Increment(key, colname, num);
        }

        public void Increment (string key, string colname, long num)
        {
            _ = RpcCacheService.FormatKey(key);
            this._Source.Increment(key, colname, num);
        }

        public void ListAppend<T> (string key, T data)
        {
            _ = RpcCacheService.FormatKey(key);
            this._Source.ListAppend(key, data);
        }

        public void ListAppend<T> (string key, T[] data)
        {
            _ = RpcCacheService.FormatKey(key);
            this._Source.ListAppend(key, data);
        }

        public void ListInsert<T> (string key, T data)
        {
            _ = RpcCacheService.FormatKey(key);
            this._Source.ListInsert(key, data);
        }

        public void ListInsert<T> (string key, T[] data)
        {
            _ = RpcCacheService.FormatKey(key);
            this._Source.ListInsert(key, data);
        }

        public void ListRemove<T> (string key, T data)
        {
            _ = RpcCacheService.FormatKey(key);
            this._Source.ListRemove(key, data);
        }

        public void ListTop (string key, int start, int end)
        {
            _ = RpcCacheService.FormatKey(key);
            this._Source.ListTop(key, start, end);
        }

        public void Remove (string key)
        {
            _ = RpcCacheService.FormatKey(key);
            this._Source.Remove(key);
        }

        public void Remove (string key, string colname)
        {
            _ = RpcCacheService.FormatKey(key);
            this._Source.Remove(key, colname);
        }

        public void Remove (string key, string[] colname)
        {
            _ = RpcCacheService.FormatKey(key);
            this._Source.Remove(key, colname);
        }

        public void Remove (string[] key)
        {
            for (int i = 0; i < key.Length; i++)
            {
                key[i] = RpcCacheService.FormatKey(key[i]);
            }
            this._Source.Remove(key);
        }

        public void Replace<T> (string key, string colname, T data)
        {
            _ = RpcCacheService.FormatKey(key);
            this._Source.Replace(key, colname, data);
        }

        public void Replace<T> (string key, T data, TimeSpan? expires = null)
        {
            _ = RpcCacheService.FormatKey(key);
            this._Source.Replace(key, data, expires);
        }

        public void Set<T> (string key, string colname, T data)
        {
            _ = RpcCacheService.FormatKey(key);
            this._Source.Set(key, colname, data);
        }

        public void Set<T> (string key, T data, TimeSpan? expires = null)
        {
            _ = RpcCacheService.FormatKey(key);
            this._Source.Set(key, data, expires);
        }

        public void Set<T> (string key, T data, DateTime expires)
        {
            _ = RpcCacheService.FormatKey(key);
            this._Source.Set(key, data, expires);
        }

        public void SetExpire (string key, DateTime time)
        {
            _ = RpcCacheService.FormatKey(key);
            this._Source.SetExpire(key, time);
        }

        public object[] Submit ()
        {
            return this._Source.Submit();
        }
    }
}
